package org.gap.web.jsf;

import java.util.List;

import org.gap.dao.NafDAO;

import org.gap.domain.Naf;

import org.gap.service.NafService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for Naf entities
 * 
 */
@Scope("session")
@Component("NafComponent")
public class NafComponentImpl implements NafComponent {

	/**
	 * Data type variable that provides CRUD operations for Naf entities
	 * 
	 */
	private Naf naf;

	/**
	 * DAO injected by Spring that manages Naf entities
	 * 
	 */
	@Autowired
	private NafDAO nafDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Naf entities
	 * 
	 */
	@Autowired
	private NafService nafService;

	/** 
	 */
	public NafComponentImpl() {
	}

	/**
	 * Create a new Naf entity
	 * 
	 */
	@Transactional
	public String newNaf() {
		naf = new Naf();

		return "/jsf/naf/createNaf.xhtml";
	}

	/**
	 * Save an existing Naf entity
	 * 
	 */
	@Transactional
	public String saveNaf(Naf naf) {
		nafService.saveNaf(naf);
		return "/jsf/naf/listNafs.xhtml";
	}

	/**
	 * Delete an existing Naf entity
	 * 
	 */
	@Transactional
	public String deleteNaf(String nafNafKey) {
		Naf naf = nafDAO.findNafByPrimaryKey(nafNafKey);
		nafService.deleteNaf(naf);
		return "/jsf/naf/listNafs.xhtml";
	}

	/**
	 * Getter for variable Naf
	 * 
	 */
	@Transactional
	public Naf getNaf() {
		return naf;
	}

	/**
	 * Select an existing Naf entity
	 * 
	 */
	@Transactional
	public String selectNaf(String nafNafKey) {
		naf = nafDAO.findNafByPrimaryKey(nafNafKey);

		return "/jsf/naf/viewNaf.xhtml";
	}

	/**
	 * Select the Naf entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteNaf(String nafNafKey) {
		naf = nafDAO.findNafByPrimaryKey(nafNafKey);

		return "/jsf/naf/deleteNaf.xhtml";
	}

	/**
	 * Edit an existing Naf entity
	 * 
	 */
	@Transactional
	public String editNaf(String nafNafKey) {
		naf = nafDAO.findNafByPrimaryKey(nafNafKey);

		return "/jsf/naf/editNaf.xhtml";
	}

	/**
	 * Show all Naf entities
	 * 
	 */
	@Transactional
	public List<Naf> listNafs() {
		return new java.util.ArrayList<Naf>(nafService.loadNafs());
	}

}
